home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Game Programming in C++ - Start to Finish
/
GameProgrammingS.iso
/
Peon
/
PeonSDK-Win32-1.0.0.exe
/
{app}
/
PeonMain
/
source
/
FileLogger.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2005-08-19
|
3KB
|
141 lines
/*
PEON - Win32 Games Programming Library
Copyright (C) 2002-2005 Erik Yuzwa
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Erik Yuzwa
book AT wazooinc DOT com
*/
#include "FileLogger.h"
namespace peon
{
template<> FileLogger* ISingleton<FileLogger>::ms_Singleton = 0;
FileLogger* FileLogger::getSingletonPtr(void)
{
return ms_Singleton;
}
FileLogger& FileLogger::getSingleton(void)
{
assert( ms_Singleton );
return ( *ms_Singleton );
}
FileLogger::FileLogger( int flags ) : m_logging_level(flags)
{
}
FileLogger::~FileLogger()
{
closeLogStream();
}
bool FileLogger::openLogStream(const String& strName)
{
m_log_file.open( strName.c_str() );
m_strLogName = strName;
logInfo("FileLogger", "************ begin logfile **********");
return true;
}
void FileLogger::closeLogStream()
{
logInfo("FileLogger", "************ end logfile **********");
m_log_file.close();
}
void FileLogger::logDebug(const String& strObject, const String& strText)
{
String strLogString;
TCHAR strOutput[MAX_PATH];
sprintf(strOutput, "[%s]| DEBUG | %s\n", strObject.c_str(), strText.c_str() );
strLogString = strOutput;
writeToLogStream( strLogString );
}
void FileLogger::logError(const String& strObject, const String& strText)
{
String strLogString;
TCHAR strOutput[MAX_PATH];
sprintf(strOutput, "[%s] | ERROR | %s\n", strObject.c_str(), strText.c_str() );
strLogString = strOutput;
writeToLogStream( strLogString );
}
void FileLogger::logInfo( const String& strObject, const String& strText)
{
String strLogString;
TCHAR strOutput[MAX_PATH];
sprintf(strOutput, "[%s] | INFO | %s\n", strObject.c_str(), strText.c_str() );
strLogString = strOutput;
writeToLogStream( strLogString );
}
void FileLogger::logFatal( const String& strObject, const String& strText)
{
String strLogString;
TCHAR strOutput[MAX_PATH];
sprintf(strOutput, "[%s] | FATAL | %s\n", strObject.c_str(), strText.c_str() );
strLogString = strOutput;
writeToLogStream( strLogString );
}
void FileLogger::writeToLogStream(const String& strText)
{
// Write time into log
struct tm *pTime;
time_t ctTime; time(&ctTime);
pTime = localtime( &ctTime );
m_log_file << std::setw(2) << std::setfill('0') << pTime->tm_hour
<< ":" << std::setw(2) << std::setfill('0') << pTime->tm_min
<< ":" << std::setw(2) << std::setfill('0') << pTime->tm_sec << ": " << strText << std::endl;
// Flush stcmdream to ensure it is written (incase of a crash, we need log to be up to date)
m_log_file.flush();
}
}